package icegps.com.pingdj.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import icegps.com.pingdj.R;
import icegps.com.pingdj.adapter.SatelliteInfoAdatper;
import icegps.com.pingdj.bean.SatelliteData;
import icegps.com.pingdj.data.ble.WriteHelper;
import icegps.com.pingdj.view.SatelliteInfoView;

/**
 * Created by 111 on 2018/3/16.
 */

public class SatelliteSignalActivity extends BaseActivity {

    @BindView(R.id.rv_gps)
    RecyclerView rvGps;
    @BindView(R.id.rv_bd)
    RecyclerView rvBd;
    @BindView(R.id.rv_glo)
    RecyclerView rvGlo;
    @BindView(R.id.satelliteInfoView)
    SatelliteInfoView satelliteInfoView;
    private ArrayList<SatelliteData> gpsData = new ArrayList<>();
    private ArrayList<SatelliteData> bdData = new ArrayList<>();
    private ArrayList<SatelliteData> gloData = new ArrayList<>();
    private SatelliteInfoAdatper gpsAdapter;
    private SatelliteInfoAdatper bdAdapter;
    private SatelliteInfoAdatper gloAdapter;

    @Override
    protected String setTitle() {
        return getString(R.string.satellite_signal);
    }

    @Override
    protected void init() {

        WriteHelper.write(WriteHelper.SATELLITE+"1");

        gpsAdapter = new SatelliteInfoAdatper(R.layout.item_satellite_info, gpsData);
        bdAdapter = new SatelliteInfoAdatper(R.layout.item_satellite_info, bdData);
        gloAdapter = new SatelliteInfoAdatper(R.layout.item_satellite_info, gloData);

        LinearLayoutManager llm = new LinearLayoutManager(activity);
        llm.setOrientation(LinearLayoutManager.HORIZONTAL);
        rvGps.setLayoutManager(llm);

        llm = new LinearLayoutManager(activity);
        llm.setOrientation(LinearLayoutManager.HORIZONTAL);
        rvBd.setLayoutManager(llm);

        llm = new LinearLayoutManager(activity);
        llm.setOrientation(LinearLayoutManager.HORIZONTAL);
        rvGlo.setLayoutManager(llm);

        rvGps.setAdapter(gpsAdapter);
        rvBd.setAdapter(bdAdapter);
        rvGlo.setAdapter(gloAdapter);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        WriteHelper.write(WriteHelper.SATELLITE+"2");
    }

    @Override
    protected int setLayout() {
        return R.layout.activity_satellite_signal;
    }

    @Override
    public void onAnalysisHexSatelliteData(ArrayList<SatelliteData> satelliteDatas, byte type) {
        switch (type) {
            case 0:
                gpsData.clear();
                gpsData.addAll(satelliteDatas);
                gpsAdapter.notifyDataSetChanged();
                break;
            case 1:
                bdData.clear();
                bdData.addAll(satelliteDatas);
                bdAdapter.notifyDataSetChanged();
                break;
            case 2:
                gloData.clear();
                gloData.addAll(satelliteDatas);
                gloAdapter.notifyDataSetChanged();
                break;
        }
        satelliteInfoView.drawSatellite(gpsData, bdData, gloData);
    }

}
